package com.tmxk.api.days01.Ysc;

import com.tmxk.api.days01.comm.Dog;

import java.util.LinkedList;

public class LinkedList_01 {
    public static void main(String[] args) {

        LinkedList<Dog>linkedList=new LinkedList<>();
        Dog dog=new Dog("小花",2);
        linkedList.add(dog);
        linkedList.add(new Dog ("花花",2));
        linkedList.add(new Dog ("小黑",2));
        linkedList.add(new Dog ("小白",2));
        linkedList.add(new Dog ("汪汪",2));

        Dog dog1=(Dog)linkedList.get(2);
        System.out.println("获取第三个下表元素的狗狗对象"+dog1);

        System.out.println("查找汪汪"+linkedList.contains("汪汪"));
        Boolean flag=false;
        for (Object obj:linkedList){
            Dog dog2=(Dog) obj;
        String stt=    "汪汪".equals(dog2.getName())==true?"":"";
        if ("汪汪".equals(dog2.getName())) {
            flag = true;
            break;

            }
        }
        System.out.println(flag==true?"包含在该集合元素中":"");

        boolean isRemo=false;
        //    arrayList.remove(arrayList.get(1));
        for (int i=0;i<linkedList.size();i++){
            Dog dog2=(Dog) linkedList.get(i);
            if ("花花".equals(dog2.getName())){
                isRemo=linkedList.remove(dog2);
            }
        }
        System.out.println(isRemo==true?"删除花花成功":"删除花花失败");

        System.out.println("\n循环遍历该集合元素");
        for (int i=0;i<linkedList.size();i++){
            System.out.println(linkedList.get(i));
        }
        /**
         * 泛型:参数化类型,
         * list接口存储的不唯一(可重置),有序(有下标的数据)
         * ArrayList实现类,动态数组,底层数据结构就是数组,优势是查询,访问效率高
         * linkedList实现类,底层数据结构就是链表,优势是新增,删除效率高
         */
        linkedList.forEach(dog2 -> {
            System.out.println(dog2);
        });
    }


}
